home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / C++ / Frameworks / GameShell / Sourcery / GameUtils.cpp < prev    next >
Encoding:
Text File  |  1995-05-11  |  2.8 KB  |  135 lines  |  [TEXT/CWIE]

  1. /*
  2. //
  3. //    generic utility routines for games
  4. //
  5. //    By:    Tony Myles
  6. //    Date:    9/19/90
  7. //
  8. //    Copyright: © 1991-93 Tony Myles, All rights reserved worldwide.
  9. */
  10.  
  11. // MODIFIED: Slightly by Hiep Dam, Sat 11/20/93
  12. // UPDATED: April 4 1995, Hiep Dam (Changed calls to PaintBehind, CalcVis
  13. //                                    for compat w/ the new universal headers.
  14.  
  15. //            April 30, 1995, Hiep Dam (Removed direct accesses to low globals
  16. //                        and added GetMenuBarRect())
  17.  
  18. // ---------------------------------------------------------------------------
  19.  
  20. #include "GameUtils.h"
  21. #include "LowMem.h"
  22.  
  23. // ---------------------------------------------------------------------------
  24.  
  25. /*
  26. //    GetRandom
  27. //
  28. //    generate a random number between min and max inclusive
  29. */
  30. unsigned short GetRandom(unsigned short min, unsigned short max)
  31. {
  32.     unsigned short random;
  33.     long range, temp;
  34.  
  35.     random = Random();
  36.     range = (max - min) + 1;
  37.     temp = (random * range) / 65536;
  38.     random = temp + min;
  39.  
  40.     return random;
  41. }
  42.  
  43. // ---------------------------------------------------------------------------
  44.  
  45. // globals for the menubar showing/hiding stuff
  46. short gMenuBarHidden = false;
  47. short gAllowedClicks;
  48. static RgnHandle gOldGrayRgn  = nil;
  49. static short gOldMBarHeight   = 0;
  50. static short padding;
  51.  
  52. // ---------------------------------------------------------------------------
  53.  
  54. void HideMenuBar(Boolean allowClicks)
  55. {
  56.     RgnHandle menuRgn;
  57.  
  58.     if (!gMenuBarHidden)
  59.     {
  60.         gOldMBarHeight = LMGetMBarHeight();
  61.         
  62.         gAllowedClicks = allowClicks;
  63.         if (!allowClicks)
  64.             LMSetMBarHeight(0);
  65.         
  66.         if (gOldGrayRgn == nil)
  67.         {
  68.             gOldGrayRgn = NewRgn();
  69.         }
  70.             
  71.         CopyRgn(LMGetGrayRgn(), gOldGrayRgn);
  72.  
  73.         menuRgn = NewRgn();
  74.         SetToMenuRect(menuRgn);
  75.         UnionRgn(LMGetGrayRgn(), menuRgn, LMGetGrayRgn());
  76.         PaintBehind(FrontWindow(), menuRgn);
  77.         CalcVisBehind(FrontWindow(), menuRgn);
  78.  
  79.          DisposeRgn(menuRgn);
  80.  
  81.         gMenuBarHidden = true;
  82.     }
  83. }
  84.  
  85.  
  86. void ShowMenuBar(void)
  87. {
  88.     if (gMenuBarHidden)
  89.     {
  90.         if (!gAllowedClicks)
  91.             LMSetMBarHeight(gOldMBarHeight);
  92.         
  93.         CopyRgn(gOldGrayRgn, LMGetGrayRgn());
  94.         SetToMenuRect(gOldGrayRgn);
  95.  
  96.         PaintBehind(FrontWindow(), gOldGrayRgn);
  97.         CalcVisBehind(FrontWindow(), gOldGrayRgn);
  98.  
  99.         DisposeRgn(gOldGrayRgn);
  100.         gOldGrayRgn = nil;
  101.  
  102.         DrawMenuBar();
  103.         gMenuBarHidden = false;
  104.     }
  105. }
  106.  
  107.  
  108. void SetToMenuRect(RgnHandle menuRgn)
  109. {
  110.     Rect menuRect;
  111.     
  112.     //menuRect = qd.screenBits.bounds;
  113.     menuRect = (**GetMainDevice()).gdRect;
  114.     menuRect.bottom = gOldMBarHeight;
  115.  
  116.     RectRgn(menuRgn, &menuRect);
  117. }
  118.  
  119. // ---------------------------------------------------------------------------
  120.  
  121. void GetMenuBarRect(Rect *mbarRect) {
  122.     *mbarRect = (**GetMainDevice()).gdRect;
  123.  
  124.     if (gMenuBarHidden)
  125.         mbarRect->bottom = gOldMBarHeight;
  126.     else
  127.         mbarRect->bottom = LMGetMBarHeight();
  128. } // END GetMenuBarRect
  129.  
  130. // ---------------------------------------------------------------------------
  131.  
  132. void Wait(long ticks) {
  133.     long dummy;
  134.     Delay(ticks, &dummy);
  135. } // END Wait